<template>
  <div class="farmer-data-analysis">
    <!-- 顶部导航栏 -->
    <div class="header-wrapper"  id="start">
      <el-header class="dashboard-header">
        <div class="header-left">
          <div class="logo">
            <i class="fas fa-leaf logo-icon"></i>
            <h1>农产品融销一体平台-农作物管理</h1>
          </div>
          <div class="location">
            <i class="fas fa-map-marker-alt"></i>
            <span>{{ userLocation }}</span>
          </div>
        </div>
        
        <div class="header-right">
          <div class="user-info">
            <div class="user-avatar">
              <img :src="user.avatar" :alt="user.name">
            </div>
            <div class="user-details">
              <div class="user-name">{{ user.name }}</div>
              <div class="user-role">{{ user.role }}</div>
            </div>
          </div>
        </div>
      </el-header>

      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        :style="{ display: 'flex', justifyContent: 'center' }"
        background-color="#2E7D32"
        text-color="#fff"
        active-text-color="#ffd04b"
      >
        <el-menu-item index="1" @click="scrollToSection('sales-section')">销售趋势</el-menu-item>
        <el-menu-item index="2" @click="scrollToSection('price-section')">市场价格监控</el-menu-item>
        <el-menu-item index="3" @click="scrollToSection('orders-section')">最近订单</el-menu-item>
        <el-menu-item index="4" @click="scrollToSection('suggestions-section')">销售建议</el-menu-item>
        <el-menu-item index="5" @click="$router.push('/farmer/index')">返回主页</el-menu-item>
      </el-menu>
  </div>
    <!-- 关键指标卡片 -->
    <div class="stats-section">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="stat-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon total-sales">
                <el-icon><Money /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-value">¥{{ formatNumber(stats.totalSales) }}</div>
                <div class="stat-label">本月销售额</div>
                <div class="stat-change" :class="getChangeClass(stats.salesChange)">
                  <el-icon v-if="stats.salesChange > 0"><Top /></el-icon>
                  <el-icon v-else-if="stats.salesChange < 0"><Bottom /></el-icon>
                  {{ Math.abs(stats.salesChange) }}%
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :span="6">
          <el-card class="stat-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon orders">
                <el-icon><ShoppingCart /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-value">{{ stats.totalOrders }}</div>
                <div class="stat-label">本月订单数</div>
                <div class="stat-change" :class="getChangeClass(stats.ordersChange)">
                  <el-icon v-if="stats.ordersChange > 0"><Top /></el-icon>
                  <el-icon v-else-if="stats.ordersChange < 0"><Bottom /></el-icon>
                  {{ Math.abs(stats.ordersChange) }}%
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :span="6">
          <el-card class="stat-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon products">
                <el-icon><Goods /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-value">{{ stats.activeProducts }}</div>
                <div class="stat-label">在售农产品</div>
                <div class="stat-change positive">
                  {{ stats.newProducts }} 个新品
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :span="6">
          <el-card class="stat-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon rating">
                <el-icon><Star /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-value">{{ stats.avgRating }}</div>
                <div class="stat-label">平均评分</div>
                <div class="stat-change positive">
                  {{ stats.totalReviews }} 条评价
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
   </div>

    <!-- 筛选条件 -->
    <div class="filter-section" id="sales-section">
      <el-card class="filter-card">
        <div class="filter-content">
          <div class="filter-item">
            <span class="filter-label">时间范围：</span>
            <el-date-picker
              v-model="filterParams.dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="YYYY-MM-DD"
              placement="bottom-start"
              @change="loadData"
            />
          </div>
          
          <div class="filter-item">
            <span class="filter-label">农产品：</span>
            <el-select
              v-model="filterParams.cropId"
              placeholder="选择农产品"
              clearable
              style="width: 200px;"
              @change="loadData"
            >
              <el-option label="全部农产品" value="" />
              <el-option
                v-for="crop in myCrops"
                :key="crop.id"
                :label="crop.name"
                :value="crop.id"
              />
            </el-select>
          </div>
          
          <div class="filter-actions">
            <el-button type="primary" @click="loadData">
              <el-icon><Search /></el-icon>
              查询
            </el-button>
            <el-button @click="resetFilters">
              <el-icon><Refresh /></el-icon>
              重置
            </el-button>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 销售数据 -->
    <div class="sales-section">
      <el-row :gutter="20">
        <el-col :span="16">
          <el-card class="chart-card">
            <template #header>
              <div class="chart-header">
                <span class="chart-title">销售趋势</span>
                <div class="chart-actions">
                  <el-radio-group v-model="salesChartType" size="small" @change="updateLineChart">
                    <el-radio-button label="daily">日度</el-radio-button>
                    <el-radio-button label="weekly">周度</el-radio-button>
                    <el-radio-button label="monthly">月度</el-radio-button>
                  </el-radio-group>
                </div>
              </div>
            </template>
            
            <!-- 折线图展示 -->
            <div class="line-chart-container">
              <div class="line-chart">
                <div class="chart-grid">
                  <!-- Y轴刻度 -->
                  <div class="y-axis">
                    <div 
                      v-for="tick in yAxisTicks" 
                      :key="tick" 
                      class="y-tick"
                    >
                      ¥{{ tick }}
                    </div>
                  </div>
                  
                  <!-- 图表内容 -->
                  <div class="chart-content">
                    <!-- 网格线 -->
                    <div 
                      v-for="tick in yAxisTicks" 
                      :key="tick" 
                      class="grid-line"
                      :style="{ bottom: `${((tick - minValue) / (maxValue - minValue)) * 100}%` }"
                    ></div>
                    
                    <!-- 数据点连线 -->
                    <div class="line-path">
                      <div 
                        v-for="(point, index) in linePoints" 
                        :key="index"
                        class="data-point"
                        :style="{
                          left: `${point.x}%`,
                          bottom: `${point.y}%`
                        }"
                      >
                        <div class="point-circle"></div>
                        <div class="point-value">¥{{ salesData[index].amount }}</div>
                      </div>
                      
                      <!-- 连线 -->
                      <svg class="line-svg" :viewBox="`0 0 100 100`" preserveAspectRatio="none">
                        <path 
                          :d="linePath" 
                          fill="none" 
                          stroke="#667eea" 
                          stroke-width="2"
                          stroke-linecap="round"
                        />
                      </svg>
                    </div>
                    
                    <!-- X轴标签 -->
                    <div class="x-axis">
                      <div 
                        v-for="(item, index) in salesData" 
                        :key="index"
                        class="x-tick"
                        :style="{ left: `${(index / (salesData.length - 1)) * 100}%` }"
                      >
                        {{ item.date }}
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :span="8">
          <el-card class="chart-card">
            <template #header>
              <div class="chart-header">
                <span class="chart-title">农产品销售占比</span>
              </div>
            </template>
            
            <!-- 简单的饼图展示 -->
            <div class="pie-chart">
              <div 
                v-for="(item, index) in cropDistribution" 
                :key="item.id"
                class="pie-item"
              >
                <div class="pie-color" :style="{ backgroundColor: getPieColor(index) }"></div>
                <div class="pie-info">
                  <span class="pie-name">{{ item.name }}</span>
                  <span class="pie-percent">{{ item.percent }}%</span>
                </div>
                <div class="pie-amount">¥{{ item.amount }}</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 价格监控 -->
    <div class="price-section" id="price-section">
      <el-card class="price-card">
        <template #header>
          <div class="price-header">
            <span class="price-title">市场价格监控</span>
            <el-button type="text" @click="refreshMarketPrices">
              <el-icon><Refresh /></el-icon>
              刷新价格
            </el-button>
          </div>
        </template>
        
        <el-table :data="marketPrices" style="width: 100%">
          <el-table-column prop="cropName" label="农产品" width="120" />
          <el-table-column prop="currentPrice" label="当前价格" width="100" align="right">
            <template #default="{ row }">
              <span class="price-value">¥{{ row.currentPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column label="价格变化" width="120" align="right">
            <template #default="{ row }">
              <span :class="getPriceChangeClass(row.change)">
                {{ formatPriceChange(row.change) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="变化率" width="100" align="right">
            <template #default="{ row }">
              <span :class="getPriceChangeClass(row.change)">
                {{ formatChangeRate(row.changeRate) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="market" label="市场" width="120" />
          <el-table-column prop="updateTime" label="更新时间" width="180">
            <template #default="{ row }">
              {{ formatTime(row.updateTime) }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="center">
            <template #default="{ row }">
              <el-button type="text" size="small" @click="viewPriceTrend(row)">
                查看趋势
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 最近订单 -->
    <div class="orders-section" id="orders-section">
      <el-card class="orders-card">
        <template #header>
          <div class="orders-header">
            <span class="orders-title">最近订单</span>
            <el-button type="text" @click="$router.push('/farmer/orders')">
              查看全部
            </el-button>
          </div>
        </template>
        
        <el-table :data="recentOrders" style="width: 100%">
          <el-table-column prop="orderNo" label="订单号" width="180" />
          <el-table-column prop="cropName" label="农产品" width="120" />
          <el-table-column prop="quantity" label="数量" width="80" align="center" />
          <el-table-column prop="amount" label="金额" width="100" align="right">
            <template #default="{ row }">
              ¥{{ row.amount }}
            </template>
          </el-table-column>
          <el-table-column prop="customer" label="买家" width="120" />
          <el-table-column prop="status" label="状态" width="100">
            <template #default="{ row }">
              <el-tag :type="getOrderStatusType(row.status)" size="small">
                {{ getOrderStatusText(row.status) }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="orderTime" label="下单时间" width="180">
            <template #default="{ row }">
              {{ formatTime(row.orderTime) }}
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 销售建议 -->
    <div class="suggestions-section" id="suggestions-section">
      <el-card class="suggestions-card">
        <template #header>
          <div class="suggestions-header">
            <span class="suggestions-title">销售建议</span>
          </div>
        </template>
        
        <div class="suggestions-content">
          <div v-for="(suggestion, index) in salesSuggestions" :key="index" class="suggestion-item">
            <el-icon class="suggestion-icon" :class="suggestion.type">
              <component :is="suggestion.icon" />
            </el-icon>
            <div class="suggestion-text">
              <div class="suggestion-title">{{ suggestion.title }}</div>
              <div class="suggestion-desc">{{ suggestion.description }}</div>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import {
  Money, ShoppingCart, Goods, Star,
  Top, Bottom, Search, Refresh,
} from '@element-plus/icons-vue'

const userLocation = ref('北京, 顺义区')

const user = ref({
  name: '张大山',
  role: '认证农夫',
  avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80'
})

//页面滑动
// 添加导航激活状态管理
const activeIndex = ref('1')

// scrollToSection 方法
const scrollToSection = (sectionId) => {
  // 更新导航激活状态
  const indexMap = {
    'sales-section': '1',
    'price-section': '2',
    'orders-section': '3',
    'suggestions-section': '4'
  }
  activeIndex.value = indexMap[sectionId] || '1'
  
  const element = document.getElementById(sectionId)
  if (element) {
    // 平滑滚动到目标元素
    window.scrollTo({
      top: element.offsetTop - 80, // 根据需要调整偏移量
      behavior: 'smooth'
    })
  }
}

// 响应式数据
const salesChartType = ref('daily')

// 筛选参数
const filterParams = reactive({
  dateRange: [],
  cropId: ''
})

// 统计数据
const stats = reactive({
  totalSales: 12850,
  salesChange: 12.5,
  totalOrders: 48,
  ordersChange: 8.3,
  activeProducts: 12,
  newProducts: 2,
  avgRating: 4.8,
  totalReviews: 36
})

// 我的农产品列表
const myCrops = ref([
  { id: 1, name: '有机西红柿' },
  { id: 2, name: '新鲜黄瓜' },
  { id: 3, name: '农家土鸡蛋' },
  { id: 4, name: '绿色白菜' },
  { id: 5, name: '甜玉米' }
])

// 销售数据
const salesData = ref([
  { date: '1月15日', amount: 1250 },
  { date: '1月16日', amount: 980 },
  { date: '1月17日', amount: 1560 },
  { date: '1月18日', amount: 890 },
  { date: '1月19日', amount: 1320 },
  { date: '1月20日', amount: 1100 },
  { date: '1月21日', amount: 1750 }
])

// 农产品销售分布
const cropDistribution = ref([
  { id: 1, name: '有机西红柿', amount: 4850, percent: 38 },
  { id: 2, name: '新鲜黄瓜', amount: 3200, percent: 25 },
  { id: 3, name: '农家土鸡蛋', amount: 2800, percent: 22 },
  { id: 4, name: '其他', amount: 2000, percent: 15 }
])

// 市场价格
const marketPrices = ref([
  { 
    cropName: '西红柿', 
    currentPrice: 8.5, 
    change: 0.3, 
    changeRate: 0.036, 
    market: '北京新发地',
    updateTime: '2024-01-21T10:00:00Z'
  },
  { 
    cropName: '黄瓜', 
    currentPrice: 6.0, 
    change: -0.2, 
    changeRate: -0.032, 
    market: '北京新发地',
    updateTime: '2024-01-21T10:00:00Z'
  },
  { 
    cropName: '土鸡蛋', 
    currentPrice: 18.8, 
    change: 0.5, 
    changeRate: 0.027, 
    market: '本地市场',
    updateTime: '2024-01-21T09:30:00Z'
  }
])

// 最近订单
const recentOrders = ref([
  {
    orderNo: 'DD20240121001',
    cropName: '有机西红柿',
    quantity: 50,
    amount: 425,
    customer: '张先生',
    status: 2,
    orderTime: '2024-01-21T09:15:00Z'
  },
  {
    orderNo: 'DD20240121002',
    cropName: '新鲜黄瓜',
    quantity: 30,
    amount: 180,
    customer: '李女士',
    status: 1,
    orderTime: '2024-01-21T08:45:00Z'
  },
  {
    orderNo: 'DD20240120003',
    cropName: '农家土鸡蛋',
    quantity: 20,
    amount: 376,
    customer: '王先生',
    status: 3,
    orderTime: '2024-01-20T16:20:00Z'
  }
])

// 销售建议
const salesSuggestions = ref([
  {
    type: 'success',
    icon: 'TrendCharts',
    title: '价格上涨建议',
    description: '西红柿市场价格上涨3.6%，建议适当提高售价'
  },
  {
    type: 'warning',
    icon: 'Warning',
    title: '库存提醒',
    description: '黄瓜库存仅剩50公斤，建议及时补充'
  },
  {
    type: 'info',
    icon: 'DataAnalysis',
    title: '销售优化',
    description: '土鸡蛋销量增长27%，考虑增加供应量'
  }
])

// 计算属性 - 折线图相关
const maxValue = computed(() => {
  const max = Math.max(...salesData.value.map(item => item.amount))
  // 向上取整到最近的500
  return Math.ceil(max / 500) * 500
})

const minValue = computed(() => {
  const min = Math.min(...salesData.value.map(item => item.amount))
  // 向下取整到最近的500
  return Math.floor(min / 500) * 500
})

const yAxisTicks = computed(() => {
  const ticks = []
  const step = (maxValue.value - minValue.value) / 4
  for (let i = 0; i <= 4; i++) {
    ticks.push(minValue.value + step * i)
  }
  return ticks.map(tick => Math.round(tick))
})

const linePoints = computed(() => {
  return salesData.value.map((item, index) => {
    const x = (index / (salesData.value.length - 1)) * 100
    const y = ((item.amount - minValue.value) / (maxValue.value - minValue.value)) * 100
    return { x, y }
  })
})

const linePath = computed(() => {
  if (linePoints.value.length === 0) return ''
  
  let path = `M ${linePoints.value[0].x} ${100 - linePoints.value[0].y}`
  for (let i = 1; i < linePoints.value.length; i++) {
    path += ` L ${linePoints.value[i].x} ${100 - linePoints.value[i].y}`
  }
  return path
})

// 方法
const formatNumber = (num) => {
  return num.toLocaleString('zh-CN')
}

const formatTime = (timeString) => {
  if (!timeString) return ''
  return new Date(timeString).toLocaleString('zh-CN')
}

const formatPriceChange = (change) => {
  if (change > 0) return `+${change.toFixed(2)}`
  if (change < 0) return `${change.toFixed(2)}`
  return '0.00'
}

const formatChangeRate = (rate) => {
  if (rate > 0) return `+${(rate * 100).toFixed(2)}%`
  if (rate < 0) return `${(rate * 100).toFixed(2)}%`
  return '0.00%'
}

const getChangeClass = (change) => {
  if (change > 0) return 'positive'
  if (change < 0) return 'negative'
  return 'neutral'
}

const getPriceChangeClass = (change) => {
  if (change > 0) return 'price-up'
  if (change < 0) return 'price-down'
  return 'price-steady'
}

const getPieColor = (index) => {
  const colors = ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57']
  return colors[index % colors.length]
}

const getOrderStatusType = (status) => {
  const types = { 1: 'warning', 2: 'success', 3: 'info', 4: 'danger' }
  return types[status] || 'info'
}

const getOrderStatusText = (status) => {
  const texts = { 1: '待发货', 2: '已发货', 3: '已完成', 4: '已取消' }
  return texts[status] || '未知'
}

const loadData = () => {
  ElMessage.success('数据加载成功')
  // 在实际项目中，这里应该是API调用
}

const resetFilters = () => {
  Object.assign(filterParams, {
    dateRange: [],
    cropId: ''
  })
  loadData()
}

const refreshMarketPrices = () => {
  ElMessage.info('正在刷新市场价格...')
  // 模拟API调用
  setTimeout(() => {
    ElMessage.success('市场价格已更新')
  }, 1000)
}

const viewPriceTrend = (row) => {
  ElMessage.info(`查看 ${row.cropName} 的价格趋势`)
}

const updateLineChart = () => {
  // 根据选择的时间粒度更新数据
  let newData = []
  if (salesChartType.value === 'daily') {
    newData = [
      { date: '1月15日', amount: 1250 },
      { date: '1月16日', amount: 980 },
      { date: '1月17日', amount: 1560 },
      { date: '1月18日', amount: 890 },
      { date: '1月19日', amount: 1320 },
      { date: '1月20日', amount: 1100 },
      { date: '1月21日', amount: 1750 }
    ]
  } else if (salesChartType.value === 'weekly') {
    newData = [
      { date: '第1周', amount: 5200 },
      { date: '第2周', amount: 4800 },
      { date: '第3周', amount: 6100 },
      { date: '第4周', amount: 5500 }
    ]
  } else {
    newData = [
      { date: '1月', amount: 21600 },
      { date: '2月', amount: 19800 },
      { date: '3月', amount: 24500 }
    ]
  }
  
  salesData.value = newData
}

onMounted(() => {
  loadData()
  scrollToSection('start')
})
</script>

<style scoped>
.farmer-data-analysis {
  min-height: 100vh;
  background: #f5f7fa;
  padding-top: 130px;
  /* 隐藏滚动条但保留滚动功能 */
  overflow-y: auto;
}

/* 固定头部容器 */
.header-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #f5f7fa;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* 头部样式 */
.dashboard-header {
  background: linear-gradient(135deg, #2E7D32 0%, #4CAF50 100%);
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 20px rgba(0,0,0,0.1);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 30px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo h1 {
  color: white;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0;
}

.logo-icon {
  font-size: 1.8rem;
  color: #FFD54F;
}

.location {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,0.9);
  font-size: 0.85rem;
  background: rgba(255,255,255,0.1);
  padding: 6px 12px;
  border-radius: 16px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  background: rgba(255,255,255,0.15) !important;
  border: 1px solid rgba(255,255,255,0.3) !important;
  color: white !important;
  transition: all 0.3s ease;
}

.action-btn:hover {
  background: rgba(255,255,255,0.25) !important;
  transform: translateY(-1px);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,0.1);
  transition: all 0.3s ease;
}

.user-info:hover {
  background: rgba(255,255,255,0.2);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.3);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-details {
  color: white;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-role {
  font-size: 0.75rem;
  opacity: 0.9;
}

/* 统计卡片 */
.stats-section {
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
  padding: 20px 0;
}

.stat-card {
  border-radius: 12px;
  border: none;
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  flex-shrink: 0;
}

.stat-icon.total-sales {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-icon.orders {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-icon.products {
  background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
}

.stat-icon.rating {
  background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 4px;
}

.stat-label {
  color: #718096;
  font-size: 14px;
  margin-bottom: 4px;
}

.stat-change {
  font-size: 12px;
  font-weight: 600;
}

.stat-change.positive {
  color: #67c23a;
}

.stat-change.negative {
  color: #f56c6c;
}

.stat-change.neutral {
  color: #909399;
}

/* 筛选区域 */
.filter-section {
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.filter-card {
  border-radius: 12px;
}

.filter-content {
  display: flex;
  align-items: center;
  gap: 20px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  color: #606266;
  font-weight: 500;
  white-space: nowrap;
}

.filter-actions {
  margin-left: auto;
}

/* 销售数据 */
.sales-section {
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.chart-card {
  border-radius: 12px;
  height: 100%;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-title {
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
}

/* 折线图样式 */
.line-chart-container {
  padding: 20px 0;
}

.line-chart {
  height: 300px;
  background: white;
  border-radius: 8px;
  position: relative;
}

.chart-grid {
  display: flex;
  height: 100%;
  position: relative;
}

.y-axis {
  width: 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 10px;
  border-right: 1px solid #e0e0e0;
}

.y-tick {
  font-size: 12px;
  color: #718096;
  text-align: right;
  padding-right: 8px;
}

.chart-content {
  flex: 1;
  position: relative;
  padding: 0 20px 30px 0;
}

.grid-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: #f0f0f0;
  z-index: 1;
}

.line-path {
  position: relative;
  width: 100%;
  height: 100%;
}

.data-point {
  position: absolute;
  transform: translate(-50%, 50%);
  z-index: 3;
}

.point-circle {
  width: 8px;
  height: 8px;
  background: #667eea;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.point-value {
  position: absolute;
  top: -25px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #2d3748;
  font-weight: 600;
  background: white;
  padding: 2px 6px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.line-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.x-axis {
  position: absolute;
  bottom: -30px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
}

.x-tick {
  font-size: 12px;
  color: #718096;
  transform: translateX(-50%);
}

/* 饼图样式 */
.pie-chart {
  padding: 20px 0;
}

.pie-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.pie-item:last-child {
  border-bottom: none;
}

.pie-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
}

.pie-info {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pie-name {
  color: #2d3748;
  font-weight: 500;
}

.pie-percent {
  color: #718096;
  font-size: 14px;
}

.pie-amount {
  color: #e53e3e;
  font-weight: 600;
  min-width: 80px;
  text-align: right;
}

/* 价格监控 */
.price-section {
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.price-card {
  border-radius: 12px;
}

.price-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price-title {
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
}

.price-value {
  font-weight: 600;
  color: #e53e3e;
}

.price-up {
  color: #f56c6c;
  font-weight: 600;
}

.price-down {
  color: #67c23a;
  font-weight: 600;
}

.price-steady {
  color: #909399;
  font-weight: 600;
}

/* 订单区域 */
.orders-section {
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.orders-card {
  border-radius: 12px;
}

.orders-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.orders-title {
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
}

/* 销售建议 */
.suggestions-section { 
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.suggestions-card {
  border-radius: 12px;
}

.suggestions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.suggestions-title {
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
}

.suggestions-content {
  padding: 8px 0;
}

.suggestion-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: #f8f9fa;
  margin-bottom: 12px;
}

.suggestion-item:last-child {
  margin-bottom: 0;
}

.suggestion-icon {
  font-size: 20px;
  margin-top: 2px;
  flex-shrink: 0;
}

.suggestion-icon.success {
  color: #67c23a;
}

.suggestion-icon.warning {
  color: #e6a23c;
}

.suggestion-icon.info {
  color: #409eff;
}

.suggestion-title {
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 4px;
}

.suggestion-desc {
  color: #718096;
  font-size: 14px;
  line-height: 1.4;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .farmer-data-analysis {
    padding: 16px;
  }
  
  .header-title {
    flex-direction: column;
    gap: 8px;
  }
  
  .header-title h1 {
    font-size: 24px;
  }
  
  .filter-content {
    flex-direction: column;
    gap: 16px;
  }
  
  .filter-item {
    width: 100%;
    justify-content: space-between;
  }
  
  .filter-actions {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }
  
  .line-chart {
    height: 250px;
  }
  
  .y-axis {
    width: 50px;
  }
  
  .point-value {
    font-size: 10px;
    top: -20px;
  }
}
</style>